﻿using System;
using System.Web.Mvc;
using System.Web.UI;
using DotNETStack.Core.Data;
using DotNETStack.Core.Web;

namespace DotNETStack.Web.UI.Controllers
{
    public class QuestionsController : BaseController
    {
        public ActionResult Index()
        {
            ViewData["title"] = Helpers.GetPageTitle("Questions");
            ViewData["Questions"] = DataProvider.QuestionRepository.GetAll(0, 10);
            return View();
        }

        public ActionResult Detail(Int32? id)
        {
            if (!id.HasValue)
            {
                return RedirectToAction("Index");
            }

            var obj = DataProvider.QuestionRepository.GetById(id.Value);
            if (obj != null)
            {
                ViewData["Question"] = obj;
                ViewData["title"] = Helpers.GetPageTitle(obj.Title);
            }
            return View();
        }

        public ActionResult Ask()
        {
            ViewData["title"] = Helpers.GetPageTitle("Ask a Question");
            return View();
        }

        public ActionResult Tagged(String tagName)
        {
            if (String.IsNullOrEmpty(tagName))
            {
                return RedirectToAction("Index");
            }

            return View();
        }
    }
}